package models.uuid;


import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.Properties;

/**
 * Hibernate主键生成器.
 */
public class RandomUUIDGenerator implements IdentifierGenerator, Configurable {

    protected static Logger log = LoggerFactory.getLogger(RandomUUIDGenerator.class);

    @Override
    public void configure(Type arg0, Properties params, Dialect arg2) throws MappingException {
        // do nothing.
    }

    @Override
    public Serializable generate(SessionImplementor arg0, Object arg1) throws HibernateException {
        return UUIDUtil.getUUID22();
    }

//    @Override
//    public void configure(Type type, Properties properties, ServiceRegistry serviceRegistry) throws MappingException {
//
//    }
//
//    @Override
//    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
//        return UUIDUtil.getUUID22();
//    }
}
